package biolabs.model.diffusion;

import jsr166y.RecursiveAction;
import biolabs.space.ContinuousPosition;
import biolabs.space.DiscretePosition;
import biolabs.space.Grid;
import biolabs.util.Transformation;

/**
 * A transformation that turns a grid of concentrations into a
 * {@link java.util.concurrent.RecursiveAction} that performs
 * diffusion on that grid.
 *
 * @param <P> position type of the gird
 * @param <C> continuous analog to {@code P}
 *
 * @author Tomas Mikula
 */
public class DiffusionTransformation<P extends DiscretePosition<P, C>, C extends ContinuousPosition<C, P>>
		implements Transformation<Grid<Double, P, C>, RecursiveAction> {

	private final Diffuser<P,C> diffuser;

	public DiffusionTransformation(Diffuser<P,C> diffuser){
		this.diffuser = diffuser;
	}

	@Override
	public RecursiveAction apply(final Grid<Double, P, C> conc) {
		return new RecursiveAction(){
			private static final long serialVersionUID = 1;

			@Override
			protected void compute() {
				diffuser.diffuse(conc);
			}
		};
	}

}
